#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File              : yAttr.py
# Author            : yang <mightyang@hotmail.com>
# Date              : 03.11.2019
# Last Modified Date: 11.12.2019
# Last Modified By  : yang <mightyang@hotmail.com>


from yBase import yBase
from yLogging import lg


class yAttr(yBase):
    def __init__(self, value=None):
        super(yAttr, self).__init__()
        self.value = value
        self.callback = []

    def __repr__(self):
        return self.value

    def setValue(self, value):
        self.value = value
        self.changedCallback()

    def addChangedCallback(self, fun, *args, **kwargs):
        self.callback.append((fun, args, kwargs))

    def changedCallback(self):
        for fun, args, kwargs in self.callback:
            try:
                fun(args, kwargs)
            except Exception as e:
                raise e


class yInt(yAttr):
    def __init__(self):
        super(yInt, self).__init__()


class yFloat(yAttr):
    def __init__(self):
        super(yFloat, self).__init__()


class yStr(yAttr):
    def __init__(self):
        super(yStr, self).__init__()


class yList(yAttr):
    def __init__(self):
        super(yList, self).__init__()


class yDict(yAttr):
    def __init__(self):
        super(yDict, self).__init__()
